package com.art.museumbackend.service.impl;

import com.art.museumbackend.entity.Articles;
import com.art.museumbackend.entity.PageBean;
import com.art.museumbackend.mapper.ArticlesMapper;
import com.art.museumbackend.service.ArticlesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yezi
 * @since 2024-12-07
 */
@Service
public class ArticlesServiceImpl extends ServiceImpl<ArticlesMapper, Articles> implements ArticlesService {

    @Autowired
    private ArticlesMapper articlesMapper;


    @Override
    public void addArticle(Articles article) {
        article.setCreatedTime(LocalDateTime.now());
        article.setUpdatedTime(LocalDateTime.now());
        articlesMapper.add(article);
    }

    @Override
    public PageBean<Articles> articleList(Integer pageNum, Integer pageSize, Integer parentColumnId,Integer subColumnId,String state) {
//        创建pagebean对象
        PageBean<Articles> pb=new PageBean<>();
//        开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<Articles> alist= articlesMapper.articleList(parentColumnId,subColumnId,state);
        System.out.println("abcd:"+alist);
        Page<Articles> p= (Page<Articles>) alist;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public Articles getArticleById(Integer articleId) {
        return articlesMapper.getArticleById(articleId);
    }

    @Override
    public void updateArticle(Articles article) {
        article.setUpdatedTime(LocalDateTime.now());
        articlesMapper.updateArticle(article);
    }

    @Override
    public void deleteArticle(Integer articleId) {
        articlesMapper.deleteArticle(articleId);
    }

    @Override
    public List<Articles> articleListById(Integer parentColumnId, Integer subColumnId) {

        List<Articles> alist= articlesMapper.articleListById(parentColumnId,subColumnId);

        return alist;
    }
}
